package com.fg.cloud.manager.service.report.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fg.cloud.common.PageUtils;
import com.fg.cloud.manager.entry.BaseEntity;
import com.fg.cloud.manager.entry.report.OrderAmountReportEntity;
import com.fg.cloud.manager.mapper.BaseMapper;
import com.fg.cloud.manager.mapper.report.OrderAmountReportMapper;
import com.fg.cloud.manager.service.BaseServiceImpl;
import com.fg.cloud.manager.service.report.OrderAmountReportService;

/**
 * Description:订单资金报表ServiceImpl
 * 
 * @author shaoqiping
 * @date 2017年9月11日下午5:44:27
 */
@Service
public class OrderAmountReportServiceImpl extends BaseServiceImpl implements OrderAmountReportService {

	@Autowired
	private OrderAmountReportMapper amountReportMapper;

	@Override
	public void findList(PageUtils<OrderAmountReportEntity> pageInfo) {
		long total = amountReportMapper.filterCount(pageInfo.getCondition());
		pageInfo.setTotal(total);
		if (total > 0) {
			List<OrderAmountReportEntity> list = amountReportMapper.findList(pageInfo);
			for (OrderAmountReportEntity orderAmountReportEntity : list) {
				orderAmountReportEntity.setAmountReceived(
						orderAmountReportEntity.getAmountPay().subtract(orderAmountReportEntity.getAmountUnreceived()));
			}
			pageInfo.setData(list);
		} else {
			pageInfo.setData(new ArrayList<OrderAmountReportEntity>());
		}
	}

	@Override
	protected <T extends BaseEntity> BaseMapper getBaseMapper() {
		return amountReportMapper;
	}

	@Override
	public List<OrderAmountReportEntity> findAll(Long facId) {
		return amountReportMapper.selectAll(facId);
	}

}
